(function (a, n) {
    var h = {
        TAB: 9,
        ENTER: 13,
        ESC: 27,
        LEFT: 37,
        UP: 38,
        RIGHT: 39,
        DOWN: 40,
        SPACEBAR: 32,
        PAGEUP: 33,
        PAGEDOWN: 34,
        F2: 113
    };
    var b = a.easyui;
    var j = /"+\\\/Date\((.*?)\)\\\/"+/g;
    var k = "tr:not(.t-grouping-row,.t-group-footer,.t-detail-row,.t-no-data,.t-footer-template):visible",
		d = ">td:not(.t-group-cell,.t-hierarchy-cell):visible",
		f = k + d + ":first",
		g = "t-state-focused";
    b.scripts.push("easyui.grid.js");

    function m(o) {
        return new Function("data", ("var p=[];with(data){p.push('" + unescape(o).replace(/[\r\t\n]/g, " ").replace(/'(?=[^#]*#>)/g, "\t").split("'").join("\\'").split("\t").join("'").replace(/<#=(.+?)#>/g, "',$1,'").split("<#").join("');").split("#>").join("p.push('") + "');}return p.join('');"))
    }
    function e(o) {
        return (o != null ? o + "" : "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
    }
    function i(q, s, r) {
        var o = a("<col />").css("width", s[r].width),
			t, u, p = 0;
        for (t = 0, u = s.length; t < u; t++) {
            if (t >= r && p) {
                break
            }
            if (!s[t].hidden) {
                p++
            }
        }
        if (t > r) {
            q.eq(p - 1).before(o)
        } else {
            q.eq(p - 1).after(o)
        }
    }
    b.grid = function (p, w) {
        var q = this;
        this.element = p;
        this.groups = [];
        this.editing = {};
        this.filterBy = "";
        this.groupBy = "";
        this.orderBy = "";
        a.extend(this, w);
        this.sorted = a.grep(this.columns, function (C) {
            return C.order
        });
        this.$tbody = a("> .t-grid-content > table > tbody", p);
        this.scrollable = this.$tbody.length > 0;
        this.$headerWrap = a("> .t-grid-header > .t-grid-header-wrap", p);
        this.$footerWrap = a("> .t-grid-footer > .t-grid-footer-wrap", p);
        if (!this.scrollable) {
            this.$tbody = a("> table > tbody", p);
            this.$header = a("> table > thead > tr", p);
            this.$footer = a("> table > tfoot", p)
        } else {
            a("> .t-grid-content", p).tScrollable();
            this.$header = a("> .t-grid-header > .t-grid-header-wrap > table > tbody > tr", p);
            this.$footer = a("> .t-grid-footer", p);
            var t = a(p).closest(".t-rtl").length,
				s = this._isRightScrollBar();
            if (t) {
                if (s) {
                    a(p).addClass("t-grid-rightscroll")
                }
            }
            var x = this.$headerWrap.add(this.$footerWrap),
				y = b.scrollbarWidth(),
				z = x.parent();
            var u = b.isTouch;
            if (u) {
                z.css("padding", "0");
                x.css({
                    width: "auto",
                    "border-width": 0
                });
                a("> .t-grid-content", p).css("width", "auto");
                var A = a("> .t-grid-content > table", p);
                A.css("table-layout", "auto");
                window.setTimeout(function () {
                    A.css("table-layout", "fixed")
                }, 1)
            } else {
                if (!t || s) {
                    z.css("padding-right", y)
                } else {
                    z.css("padding-left", y)
                }
                if (y == 0) {
                    x.css("border-width", 0)
                }
            }
            a("> .t-grid-content", p).bind("scroll", function () {
                if (q.pageOnScroll) {
                    var C = this.scrollTop + this.clientHeight;
                    if (C === this.scrollHeight && q.currentPage < q.totalPages() && !q._pagingInProgress) {
                        q._pagingInProgress = true;
                        q.pageTo(q.currentPage + 1)
                    }
                }
                x.scrollLeft(this.scrollLeft)
            })
        }
        if (this.rowTemplate) {
            this.rowTemplate = m(this.rowTemplate)
        }
        this.$tbody.delegate(".t-hierarchy-cell .t-plus, .t-hierarchy-cell .t-minus", "click", b.stopAll(function (F) {
            var C = a(F.target);
            var G = C.hasClass("t-plus");
            C.toggleClass("t-minus", G).toggleClass("t-plus", !G);
            var D = C.closest("tr.t-master-row");
            if (this.detail && !D.next().hasClass("t-detail-row")) {
                var E = 0;
                a.each(this.columns, function () {
                    if (!this.hidden) {
                        E++
                    }
                });
                a(new b.stringBuilder().cat('<tr class="t-detail-row').catIf(" t-alt", D.hasClass("t-alt")).cat('">').rep('<td class="t-group-cell"></td>', D.find(".t-group-cell").length).cat('<td class="t-hierarchy-cell"></td>').cat('<td class="t-detail-cell" colspan="').cat(E).cat('">').cat(this.displayDetails(this.dataItem(D))).cat("</td></tr>").string()).insertAfter(D)
            }
            b.trigger(this.element, G ? "detailViewExpand" : "detailViewCollapse", {
                masterRow: D[0],
                detailRow: D.next(".t-detail-row")[0]
            });
            D.next().toggle(G)
        }, this));
        this.$pager = a("> .t-grid-pager .t-pager", p);
        var o = new b.dropDown({
            effects: b.fx.slide.defaults(),
            onClick: a.proxy(function (C) {
                this.changePageSize(a(C.item).text());
                o.close()
            }, this)
        });
        a(p).delegate(".t-button", "click", a.proxy(function (C) {
            this._command(C)
        }, this));
        o.dataBind(w.pageSizesInDropDown || []);
        a(document.documentElement).bind("mousedown", function (C) {
            var D = o.$element[0];
            if (!a.contains(D, C.target)) {
                o.close()
            }
        });
        this.$pager.delegate(".t-state-disabled", "click", b.preventDefault).delegate(".t-link:not(.t-state-disabled)", "mouseenter", b.hover).delegate(".t-link:not(.t-state-disabled)", "mouseleave", b.leave).delegate("input[type=text]", "keydown", a.proxy(this.pagerKeyDown, this)).delegate(".t-page-size .t-dropdown-wrap", "click", function () {
            var C = a(this);
            o.open({
                offset: C.offset(),
                outerHeight: C.outerHeight(),
                outerWidth: C.outerWidth(),
                zIndex: b.getElementZIndex(this)
            })
        });
        a("> .t-grid-pager", p).delegate(".t-refresh", "click", a.proxy(this.refreshClick, this));
        a(p).delegate(".t-button", "hover", b.preventDefault);
        if (this.sort) {
            this.$header.delegate("a.t-link", "hover", function () {
                a(this).toggleClass("t-state-hover")
            })
        }
        var v = "tr:not(.t-grouping-row,.t-detail-row,.t-no-data,.t-group-footer,:has(>.t-edit-container))";
        if (this.selectable) {
            var B = this.$tbody[0];
            this.$tbody.delegate(v, "click", function (C) {
                if (this.parentNode == B) {
                    q.rowClick(C)
                }
            }).delegate(v, "hover", function (C) {
                if (this.parentNode == B) {
                    if (C.type == "mouseenter") {
                        a(this).addClass("t-state-hover")
                    } else {
                        a(this).removeClass("t-state-hover")
                    }
                }
            })
        }
        if (this.isAjax() || this.operationMode === "client") {
            this.$pager.delegate(".t-link:not(.t-state-disabled)", "click", b.stop(this.pagerClick, this));
            if (this.sort) {
                this.$header.delegate("a.t-link", "click", b.stop(this.headerClick, this))
            }
        }
        for (var r = 0; r < this.plugins.length; r++) {
            b[this.plugins[r]].initialize(this)
        }
        b.bind(this, {
            columnResize: this.onColumnResize,
            columnReorder: this.onColumnReorder,
            command: this.onCommand,
            complete: this.onComplete,
            "delete": this.onDelete,
            detailViewExpand: this.onDetailViewExpand,
            detailViewCollapse: this.onDetailViewCollapse,
            dataBinding: this.onDataBinding,
            dataBound: this.onDataBound,
            edit: this.onEdit,
            error: this.onError,
            load: this.onLoad,
            rowSelect: this.onRowSelect,
            rowDataBound: this.onRowDataBound,
            save: this.onSave,
            submitChanges: this.onSubmitChanges,
            columnHide: this.onColumnHide,
            columnShow: this.onColumnShow
        });
        this.initializeColumns();
        if (this.keyboardNavigation) {
            this.initializeNavigation()
        }
        if (this.isAjax() || this.operationMode === "client") {
            this._dataSource()
        }
        if (this.columnContextMenu) {
            this.initializeContextMenu()
        }
    };
    b.grid.prototype = {
        initializeNavigation: function () {
            var r = this,
				o = a(r.element).attr("tabIndex", 0),
				p = "keydown",
				q = a.proxy(r._keyDown, r);
            r._initNavigationMouseEvents();
            o.bind({
                focus: function (t) {
                    var s = r.current();
                    if (s) {
                        s.addClass(g)
                    } else {
                        if (s = r.$tbody.find("td." + g).eq(0), s.length) {
                            r._current = s
                        } else {
                            r.current(o.find(f))
                        }
                    }
                },
                focusin: function (s) {
                    var t = a(s.target).closest("td");
                    if (t.parent().hasClass("t-grid-new-row")) {
                        r.current(t)
                    }
                },
                focusout: function () {
                    if (r._current) {
                        r._current.removeClass(g)
                    }
                },
                keydown: q
            });
            if (r.editing && r.editing.mode == "PopUp") {
                o.bind("edit", function (s) {
                    a(s.form).bind(p, q)
                });
                a("#" + r.formId() + ":visible").bind(p, q)
            }
            if (r.pageOnScroll) {
                o.bind("dataBinding", function () {
                    var t = r.current(),
						u = t ? t.parent().index(k) - 1 : 0,
						s = t ? t.index() : 0;
                    o.one("dataBound", function () {
                        var v = r.$tbody.find(k);
                        r._focusGridElement();
                        if (r._current) {
                            r._current.removeClass(g)
                        }
                        r._current = v.eq(u).children().eq(s).addClass(g)
                    })
                })
            }
        },
        _onCommand: function (o) {
            if (o.row) {
                o.dataItem = this.dataItem(o.row)
            }
            return b.trigger(this.element, "command", o)
        },
        _onComplete: function (o) {
            return b.trigger(this.element, "complete", o)
        },
        _command: function (q) {
            var p = a(q.currentTarget);
            var r = p.closest(".t-grid")[0];
            if (p.is(".t-ajax") && r == this.element) {
                var s = /t-grid-([^\s]*)/.exec(p.attr("class"));
                if (s) {
                    s = s[1]
                }
                var o = {
                    name: s,
                    row: p.closest("tr")[0]
                };
                q.preventDefault();
                if (this._onCommand(o)) {
                    return
                }
                a.ajax(this.ajaxOptions({
                    url: p.attr("href"),
                    data: o.data || {},
                    success: a.proxy(function (t) {
                        try {
                            t = eval("(" + t + ")")
                        } catch (u) {
                            if (!b.ajaxError(this.element, "error", xhr, "parsererror")) {
                                alert("Error! The requested URL did not return JSON.")
                            }
                            return
                        }
                        this._onComplete({
                            name: s,
                            response: t
                        })
                    }, this)
                }))
            }
        },
        _keyDown: function (u) {
            var F = this,
				w = a(F.element),
				E = F.$tbody,
				z = w.closest(".t-rtl").length,
				A = u.keyCode,
				t = "dataBound",
				s = a.proxy(F.current, F),
				r = s(),
				B = F.$pager.length > 0,
				q = F.selectable,
				C = E.has("tr>td>.t-grid-select").length > 0,
				D = a(u.target),
				o = !D.is(":button,a,:input,a>.t-icon"),
				v = F.editRow,
				y = false,
				p;
            if (!r) {
                if (F.editing && F.editing.mode == "PopUp") {
                    r = F._current = w.find(f)
                } else {
                    return
                }
            }
            p = r.index();
            if (!a.browser.msie) {
                o = o && D[0] === w[0]
            }
            if (o) {
                if (B && h.PAGEDOWN == A) {
                    if (!F.pageOnScroll) {
                        w.one(t, function () {
                            s(w.find(f));
                            F._focusGridElement()
                        })
                    }
                    if (F.currentPage < F.totalPages()) {
                        F.pageTo(F.currentPage + 1)
                    }
                    y = true
                } else {
                    if (B && h.PAGEUP == A) {
                        if (!F.pageOnScroll) {
                            w.one(t, function () {
                                s(w.find(f));
                                F._focusGridElement()
                            });
                            if (F.currentPage > 1) {
                                F.pageTo(Math.max(F.currentPage - 1, 1))
                            }
                        }
                        y = true
                    } else {
                        if (h.UP === A) {
                            s(r ? r.parent().prevAll(k).last().children(":eq(" + p + "),:eq(0)").last() : w.find(f));
                            y = true
                        } else {
                            if (h.DOWN === A) {
                                s(r ? r.parent().nextAll(k).first().children(":eq(" + p + "),:eq(0)").last() : w.find(f));
                                y = true
                            } else {
                                if (h.LEFT === A) {
                                    if (r) {
                                        if (z) {
                                            r = r.nextAll(":visible:first")
                                        } else {
                                            r = r.prevAll(":not(.t-group-cell, .t-hierarchy-cell):visible:first")
                                        }
                                    } else {
                                        r = w.find(f)
                                    }
                                    s(r);
                                    y = true
                                } else {
                                    if (h.RIGHT === A) {
                                        if (r) {
                                            if (z) {
                                                r = r.prevAll(":not(.t-group-cell, .t-hierarchy-cell):visible:first")
                                            } else {
                                                r = r.nextAll(":visible:first")
                                            }
                                        } else {
                                            r = w.find(f)
                                        }
                                        s(r);
                                        y = true
                                    } else {
                                        if ((q || C) && h.SPACEBAR == A) {
                                            y = true;
                                            var x = r.parent().find(".t-grid-select:first").andSelf();
                                            if (C && x[1]) {
                                                location.href = x[1].href
                                            } else {
                                                if (q) {
                                                    x.click()
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (!y && v && !D.is(":button,a,a>.t-icon")) {
                y = F._handleEditing(u)
            }
            if (y) {
                u.preventDefault();
                u.stopPropagation()
            }
        },
        _handleEditing: function (r) {
            var I = this,
				C = r.keyCode,
				G = r.shiftKey,
				D, q = a.proxy(I.current, I),
				o = a.proxy(I._clearInputSelection, I),
				v = a.proxy(I._focusGridElement, I),
				p = q(),
				t = a(I.element),
				H = I.$tbody,
				E = p.parent(),
				F = E.index(),
				J, w = false,
				s = "td.t-grid-edit-cell",
				u = ":input:visible:first",
				x = I.isAjax(),
				A = E.closest("tr.t-grid-new-row")[0],
				z = I.editing.mode === "InCell",
				B = I.editing.mode === "PopUp",
				y = E.closest("tr.t-grid-edit-row")[0] || (B && a("#" + I.formId() + ":visible").length);
            if (h.ENTER == C || h.F2 == C) {
                w = true;
                if (y) {
                    if (a(r.target).is("textarea")) {
                        w = false;
                        return
                    }
                    o(p.find(u)[0]);
                    if (z) {
                        J = I.validate();
                        if (!J) {
                            p.find(u).focus();
                            return
                        }
                        if (p.is(s)) {
                            I.saveCell(p[0])
                        } else {
                            E.find(s).each(function () {
                                I.saveCell(this)
                            });
                            I.editCell(p[0])
                        }
                        if (I.valid) {
                            v()
                        }
                    } else {
                        if (x) {
                            t.one("dataBound", function () {
                                var K = a(this).data("tGrid");
                                K._current = K.$tbody.children().eq(F).find(d).eq(0);
                                v()
                            });
                            if (B) {
                                a(".t-grid-update,.t-grid-insert", "#" + I.formId()).click()
                            } else {
                                if (A) {
                                    I.insertRow(E)
                                } else {
                                    I.updateRow(E)
                                }
                            }
                        } else {
                            if (I.validate()) {
                                if (B) {
                                    E = a("#" + I.formId())
                                }
                                E.find(".t-grid-update,.t-grid-insert").click()
                            }
                        }
                    }
                } else {
                    if (z) {
                        H.find(s).each(function () {
                            I.saveCell(this)
                        });
                        I.editCell(p[0])
                    } else {
                        if (x) {
                            I.editRow(E);
                            q(E.children().eq(0));
                            if (B) {
                                E = a("#" + I.formId())
                            }
                            E.find(u).focus()
                        } else {
                            location.href = E.find(".t-grid-edit:first").attr("href")
                        }
                    }
                }
            } else {
                if (h.ESC == C && y) {
                    w = true;
                    o(p.find(u)[0]);
                    if (z && p.is(s)) {
                        I.cancelCell(p);
                        v()
                    } else {
                        if (x) {
                            if (B) {
                                a(".t-grid-cancel", "#" + this.formId()).click()
                            } else {
                                I.cancelRow(E)
                            }
                            q(E.find(d).eq(0));
                            v()
                        } else {
                            if (B) {
                                E = a("#" + I.formId())
                            }
                            location.href = E.find(".t-grid-cancel:first").attr("href")
                        }
                    }
                } else {
                    if (z && h.TAB == C) {
                        if (y) {
                            o(p.find(u)[0]);
                            I.saveCell(p);
                            if (I.valid) {
                                v()
                            } else {
                                p.find(u).focus();
                                return true
                            }
                            w = true
                        }
                        D = G ? p.prevAll(":not(.t-group-cell, .t-hierarchy-cell):visible:first") : p.nextAll(":visible:first");
                        if (!D.length) {
                            D = p.parent()[G ? "prevAll" : "nextAll"](k).children(G ? ":not(.t-group-cell, .t-hierarchy-cell):visible:last" : ":not(.t-group-cell, .t-hierarchy-cell):visible:first")
                        }
                        q(D);
                        if (I.keyboardNavigation.editOnTab && D.length) {
                            I.editCell(D[0]);
                            setTimeout(function () {
                                if (D.hasClass("t-grid-edit-cell")) {
                                    D.find(u).focus()
                                }
                            });
                            w = true
                        }
                    }
                }
            }
            return w
        },
        _initNavigationMouseEvents: function () {
            var y = this,
				x = y.$tbody,
				v = k + d,
				o = a.browser,
				p = "click",
				s = "mousedown",
				q, w, r, t = ".t-grid-edit-row",
				u = ":button,a,:input,a>.t-icon";
            if (o.msie) {
                x.delegate(v, p, function (z) {
                    w = a(z.target), r = a(z.currentTarget), q = y._current;
                    if (r.closest("tbody")[0] !== x[0]) {
                        return
                    }
                    if (w.is(u)) {
                        if (!(q && !r.parent().is(t))) {
                            if (q) {
                                q.removeClass(g)
                            }
                            y._current = r
                        }
                    } else {
                        if (q && q[0] === r[0]) {
                            y._current = null
                        }
                        y.current(r);
                        z.preventDefault()
                    }
                })
            } else {
                x.delegate(v, s, function (z) {
                    w = a(z.target), r = a(z.currentTarget), q = y._current;
                    if (r.closest("tbody")[0] !== x[0]) {
                        return
                    }
                    if (w.is(u)) {
                        if (!(q && !r.parent().is(t))) {
                            if (q) {
                                q.removeClass(g)
                            }
                            y._current = r
                        }
                    } else {
                        y.current(r)
                    }
                })
            }
        },
        _clearInputSelection: function (p) {
            if (!p || a(p).is(":checkbox, :radio")) {
                return
            }
            var o = a.browser,
				q;
            if (o.msie && parseInt(o.version) == 8) {
                q = p.createTextRange();
                q.moveStart("textedit", 1);
                q.select()
            }
        },
        _focusGridElement: function () {
            var o = a.browser;
            if (o.msie && parseInt(o.version) < 9) {
                a("body", document).focus()
            }
            this.element.focus()
        },
        current: function (p) {
            var q = this,
				o = q._current;
            if (p !== n && p.length) {
                if (!o || o[0] !== p[0]) {
                    p.addClass(g);
                    if (o) {
                        o.removeClass(g)
                    }
                    q._current = p;
                    q._scrollTo(p.parent()[0])
                }
            } else {
                return q._current
            }
        },
        _scrollTo: function (s) {
            var p = this.$tbody.closest("div.t-grid-content")[0];
            if (!s || !p) {
                return
            }
            var u = s.offsetTop,
				t = s.offsetHeight,
				r = p.scrollTop,
				q = p.clientHeight,
				o = u + t;
            p.scrollTop = r > u ? u : o > (r + q) ? o - q : r
        },
        _isRightScrollBar: function () {
            var o = 536;
            return (a.browser.webkit && parseInt(a.browser.version, 10) < o) || (a.browser.mozilla && parseInt(a.browser.version, 10) < 2)
        },
        _transformParams: function (o) {
            var t = this,
				s = t._isServerOperation(),
				r = {},
				p = t.filterBy || "",
				q = t.orderBy || "";
            if (s) {
                if (o.page) {
                    r[t.queryString.page] = o.page
                }
                if (o.pageSize) {
                    r[t.queryString.size] = o.pageSize
                }
                if (q !== "") {
                    r[t.queryString.orderBy] = q
                }
                if (p !== "") {
                    r[t.queryString.filter] = p
                }
                if (t.groupBy) {
                    r[t.queryString.groupBy] = t.groupBy
                }
                if (o.aggregates && o.aggregates.length) {
                    r.aggregates = a.map(t.columns, function (u) {
                        if (u.aggregates) {
                            return u.member + "-" + u.aggregates.join("-")
                        }
                    }).join("~")
                }
            }
            delete o.page;
            delete o.pageSize;
            delete o.sort;
            delete o.filter;
            delete o.group;
            delete o.aggregates;
            if (t.ws) {
                r = b.toJson(a.extend(o, {
                    state: r
                }))
            } else {
                r = a.extend(r, o)
            }
            return r
        },
        _dataSourceOptions: function () {
            var u = this,
				s = this.pageSize > 0,
				r, p = u.data || [],
				t = u._isServerOperation(),
				o = a.map(u.columns || [], function (v) {
				    return a.map(v.aggregates || [], function (w) {
				        return {
				            field: v.member,
				            aggregate: w
				        }
				    })
				}),
				q = {
				    translateGroup: function (v) {
				        return {
				            value: v.Key,
				            hasSubgroups: v.HasSubgroups,
				            aggregates: v.Aggregates,
				            items: v.HasSubgroups ? a.map(v.Items, a.proxy(this.translateGroup, this)) : v.Items
				        }
				    },
				    flatGroups: function (v) {
				        if (v.HasSubgroups) {
				            return this.flatGroups(v.Items)
				        }
				        return v.Items
				    },
				    convert: function (v) {
				        return v.d || v
				    },
				    mergeChanges: function (v, D, x) {
				        var z, A, C, B = [],
							y, w = u.dataSource;
				        a.each(x, function (F, E) {
				            for (A = 0, C = v.length; A < C; A++) {
				                if (E === w.id(v[A])) {
				                    v.splice(A, 1);
				                    break
				                }
				            }
				        });
				        a.each(D, function (E, F) {
				            z = w.id(this);
				            y = false;
				            for (A = 0, C = v.length; A < C; A++) {
				                if (z === w.id(v[A])) {
				                    a.extend(true, v[A], F);
				                    y = true;
				                    break
				                }
				            }
				            if (!y) {
				                B.push(F)
				            }
				        });
				        return v.concat(B)
				    },
				    data: function (w) {
				        var x = u.dataSource,
							v = x.data(),
							z = x.page() - 1,
							A = x.pageSize(),
							y = u.deletedIds || [];
				        u.deletedIds = [];
				        if (w) {
				            w = this.convert(w);
				            w = !a.isArray(w) ? w.data || w.Data : w;
				            if (v && v.length && !t && x.id) {
				                if (w.length && typeof w[0].HasSubgroups != "undefined" && !t) {
				                    w = a.map(w, a.proxy(this.flatGroups, this))
				                }
				                return this.mergeChanges(v, w, y)
				            }
				        }
				        return w
				    },
				    total: function (v) {
				        if (v) {
				            v = this.convert(v);
				            return !a.isArray(v) ? v.total || v.Total || 0 : v.length
				        }
				        return 0
				    },
				    groups: function (v) {
				        v = this.data(v);
				        return a.map(v, a.proxy(this.translateGroup, this))
				    },
				    aggregates: function (v) {
				        v = this.convert(v);
				        return v.aggregates || {}
				    }
				};
            r = {
                serverSorting: t,
                serverPaging: t,
                serverFiltering: t,
                serverGrouping: t,
                serverAggregates: t,
                page: s ? u.currentPage : n,
                pageSize: s ? u.pageSize : n,
                aggregates: u.aggregates || o,
                error: a.proxy(function (v) {
                    var x = v[0],
						w = v[1];
                    if (b.ajaxError(this.element, "error", x, w)) {
                        return
                    }
                }, this),
                group: a.map(u.groups || [], function (v) {
                    return {
                        field: v.member,
                        dir: v.order,
                        aggregates: o
                    }
                }),
                sort: a.map(u.sorted, function (v) {
                    return {
                        field: v.member,
                        dir: v.order
                    }
                }),
                filter: a.map(a.grep(u.columns, function (v) {
                    return v.filters
                }), function (v) {
                    return a.map(v.filters, function (x) {
                        var y = x.filters,
							A, B, C;
                        if (y) {
                            for (A = 0, B = y.length; A < B; A++) {
                                C = y[A].value;
                                if (v.type == "Number") {
                                    C = parseFloat(C)
                                } else {
                                    if (v.type == "Date") {
                                        if (typeof C === "string") {
                                            var w = /^\/Date\((.*?)\)\/$/.exec(C);
                                            if (w) {
                                                C = new Date(parseInt(w[1]))
                                            } else {
                                                var z = v.format ? /\{0(:([^\}]+))?\}/.exec(v.format)[2] : b.cultureInfo.shortDate;
                                                C = b.datetime.parse({
                                                    value: C,
                                                    format: z
                                                }).toDate()
                                            }
                                        }
                                    }
                                }
                                y[A].value = C;
                                y[A].field = v.member
                            }
                        }
                        return x
                    })
                })
            };
            if (t || (u.isAjax() && !p.length)) {
                a.extend(r, {
                    transport: {
                        dialect: {
                            read: a.proxy(u._transformParams, this)
                        },
                        read: {
                            type: "POST",
                            dataType: "text",
                            dataFilter: function (v, w) {
                                v = eval("(" + v.replace(j, "new Date($1)") + ")");
                                u._onComplete({
                                    name: "dataBinding",
                                    response: v
                                });
                                return v
                            },
                            contentType: u.ws ? "application/json; charset=utf-8" : n,
                            complete: a.proxy(u.hideBusy, u)
                        }
                    },
                    deserializer: q
                })
            } else {
                if (p.length) {
                    a.extend(r, {
                        data: {
                            data: u.data,
                            total: u.total || p.length
                        },
                        deserializer: q
                    })
                }
            }
            return r
        },
        _dataSource: function () {
            var q = this,
				p = q._dataSourceOptions(),
				o = p.data;
            q.dataSource = new b.DataSource(p);
            if (o && o.data) {
                q._convertInitialData(o.data)
            }
            q.dataSource.bind("change", a.proxy(q._dataChange, q))
        },
        _convertInitialData: function (o) {
            var t = this;
            if (!t._isServerOperation() && o && o.length) {
                t.dataSource.read();
                var u = t.dataSource.view();
                if (u.length && u[0].hasSubgroups != n) {
                    var s = [],
						p = function (v) {
						    if (v.hasSubgroups) {
						        return p(v.items)
						    }
						    return v.items
						};
                    for (var q = 0, r = u.length; q < r; q++) {
                        s = s.concat(p(u[q]))
                    }
                    t.data = s
                } else {
                    t.data = u
                }
            }
        },
        _mapAggregates: function (o) {
            var q = {};
            for (var p in o) {
                q[p.replace(/^\w/, function (r) {
                    return r.toUpperCase()
                })] = o[p]
            }
            return q
        },
        rowClick: function (q) {
            var p = a(q.target);
            if (!p.is(":button,a,.t-delete,input,select,textarea,option,a>.t-icon")) {
                q.stopPropagation();
                var o = p.closest("tr").addClass("t-state-selected").siblings().removeClass("t-state-selected").end();
                b.trigger(this.element, "rowSelect", {
                    row: o[0]
                })
            }
        },
        $rows: function () {
            return this.$tbody.find("> tr:not(.t-grouping-row,.t-detail-row)")
        },
        expandRow: function (o) {
            a(o).find("> td .t-plus, > td .t-expand").click()
        },
        collapseRow: function (o) {
            a(o).find("> td .t-minus, > td .t-collapse").click()
        },
        headerClick: function (o) {
            o.preventDefault();
            this.toggleOrder(this.$columns().index(a(o.target).closest("th")));
            this.sort(this.sortExpr())
        },
        refreshClick: function (o, p) {
            if (a(p).is(".t-loading")) {
                return
            }
            if (this.isAjax()) {
                o.preventDefault();
                if (!this._isServerOperation()) {
                    this.dataSource.data([])
                }
                this.ajaxRequest()
            }
        },
        sort: function (o) {
            this.orderBy = o;
            this.ajaxRequest()
        },
        columnFromTitle: function (p) {
            p = a.trim(p);
            var o = a.grep(this.$columns(), function (q) {
                return a.trim(a(q).text()) == p
            })[0];
            if (o) {
                return this.columns[this.$columns().index(o)]
            }
            return a.grep(this.columns, function (q) {
                return q.title == p
            })[0]
        },
        columnFromMember: function (p) {
            var o = a.grep(this.columns, function (q) {
                return q.member == p
            })[0];
            if (!o) {
                o = a.grep(this.columns, function (q) {
                    var r = "." + q.member;
                    return p.substr(p.length - r.length) == r
                })[0]
            }
            return o
        },
        toggleOrder: function (o) {
            o = typeof o == "number" ? this.columns[o] : o;
            var p = "asc";
            if (o.order == "asc") {
                p = "desc"
            } else {
                if (o.order == "desc") {
                    if (this.allowUnsort === false) {
                        p = "asc"
                    } else {
                        p = null
                    }
                }
            }
            o.order = p;
            var q = a.inArray(o, this.sorted);
            if (this.sortMode == "single" && q < 0) {
                a.each(this.sorted, function () {
                    this.order = null
                });
                this.sorted = []
            }
            if (q < 0 && p) {
                this.sorted.push(o)
            }
            if (!p) {
                this.sorted.splice(q, 1)
            }
        },
        sortExpr: function () {
            return a.map(this.sorted, function (o) {
                return o.member + "-" + o.order
            }).join("~")
        },
        pagerKeyDown: function (o) {
            if (o.keyCode == 13) {
                var p = this.sanitizePage(a(o.target).val());
                if (p != this.currentPage) {
                    this.pageTo(p)
                } else {
                    a(o.target).val(p)
                }
                o.preventDefault()
            }
        },
        isAjax: function () {
            return this.ajax || this.ws || this.onDataBinding
        },
        url: function (o) {
            return (this.ajax || this.ws)[o]
        },
        pagerClick: function (p) {
            p.preventDefault();
            var o = a(p.target).closest(".t-link");
            var s = this.currentPage;
            var t = o.find(".t-icon");
            if (t.hasClass("t-arrow-next")) {
                s++
            } else {
                if (t.hasClass("t-arrow-last")) {
                    s = this.totalPages()
                } else {
                    if (t.hasClass("t-arrow-prev")) {
                        s--
                    } else {
                        if (t.hasClass("t-arrow-first")) {
                            s = 1
                        } else {
                            var r = o.text();
                            if (r == "...") {
                                var q = o.parent().children().index(o);
                                if (q == 0) {
                                    s = parseInt(o.next().text()) - 1
                                } else {
                                    s = parseInt(o.prev().text()) + 1
                                }
                            } else {
                                s = parseInt(r)
                            }
                        }
                    }
                }
            }
            this.pageTo(isFinite(s) ? s : this.currentPage)
        },
        changePageSize: function (p) {
            var o = parseInt(p, 10);
            if (isNaN(o) || o < 1) {
                return this.pageSize
            }
            o = Math.max(o, 1);
            this.currentPage = 1;
            this.pageSize = o;
            if (this.isAjax()) {
                this.ajaxRequest()
            } else {
                this.serverRequest()
            }
        },
        pageTo: function (o) {
            this.currentPage = o;
            if (this.isAjax()) {
                this.ajaxRequest()
            } else {
                this.serverRequest()
            }
        },
        _dataChange: function () {
            var p = this.dataSource;
            if (!this._clientBindingInProgress) {
                this.total = p.total()
            }
            this.aggregates = p.aggregates();
            var o = p.view();
            if (this.pageOnScroll && this._pagingInProgress === true) {
                o = (this.data || []).concat(o);
                this._pagingInProgress = false
            }
            this._current = null;
            this._populate(o)
        },
        _populate: function (o) {
            this.data = [];
            this.bindTo(o);
            this.bindFooter();
            this.updatePager();
            this.updateSorting();
            b.trigger(this.element, "dataBound");
            b.trigger(this.element, "repaint")
        },
        ajaxOptions: function (o) {
            var p = {
                type: "POST",
                dataType: "text",
                dataFilter: function (r, s) {
                    return r.replace(j, "new Date($1)")
                },
                error: a.proxy(function (s, r) {
                    if (b.ajaxError(this.element, "error", s, r)) {
                        return
                    }
                }, this),
                complete: a.proxy(this.hideBusy, this),
                success: a.proxy(function (r, t, u) {
                    try {
                        r = eval("(" + r + ")")
                    } catch (s) {
                        if (!b.ajaxError(this.element, "error", u, "parsererror")) {
                            alert("Error! The requested URL did not return JSON.")
                        }
                        return
                    }
                    if (o.commandName) {
                        this._onComplete({
                            name: o.commandName,
                            response: r
                        })
                    }
                    r = r.d || r;
                    if (o.hasErrors && o.hasErrors(r)) {
                        if (!b.trigger(this.element, "error", {
                            XMLHttpRequest: u,
                            textStatus: "modelstateerror",
                            modelState: r.modelState
                        })) {
                            o.displayErrors(r)
                        }
                        return
                    }
                    this.dataSource.success(r)
                }, this)
            };
            a.extend(p, o);
            var q = this.ws ? p.data.state = {} : p.data;
            if (this._isServerOperation()) {
                q[this.queryString.page] = this.currentPage;
                q[this.queryString.size] = this.pageSize;
                q[this.queryString.groupBy] = this.groupBy;
                q[this.queryString.filter] = (this.filterBy || "").replace(/\"/g, '\\"')
            }
            q[this.queryString.orderBy] = this.orderBy || "";
            q[this.queryString.aggregates] = a.map(this.columns, function (r) {
                if (r.aggregates) {
                    return r.member + "-" + r.aggregates.join("-")
                }
            }).join("~");
            if (this.ws) {
                p.data = b.toJson(p.data);
                p.contentType = "application/json; charset=utf-8"
            }
            return p
        },
        showBusy: function () {
            this.busyTimeout = setTimeout(a.proxy(function () {
                a("> .t-grid-pager .t-status .t-icon", this.element).addClass("t-loading")
            }, this), 100)
        },
        hideBusy: function () {
            clearTimeout(this.busyTimeout);
            a("> .t-grid-pager .t-status .t-icon", this.element).removeClass("t-loading")
        },
        serverRequest: function () {
            if (this.operationMode === "client") {
                this.ajaxRequest()
            } else {
                location.href = b.formatString(unescape(this.urlFormat), this.currentPage, this.orderBy || "~", this.groupBy || "~", encodeURIComponent(this.filterBy) || "~", this.pageSize || "~")
            }
        },
        _isServerOperation: function () {
            return this.operationMode !== "client"
        },
        ajaxRequest: function (o) {
            var u = this,
				t = u.pageSize > 0,
				s = u.pageSize,
				q = u.currentPage,
				p = a.map(u.columns, function (v) {
				    return a.map(v.aggregates || [], function (w) {
				        return {
				            field: v.member,
				            aggregate: w
				        }
				    })
				});
            if (q > 1 && u.pageOnScroll && !u._pagingInProgress) {
                s = q * u.pageSize;
                q = 1
            }
            var r = {
                page: q,
                sortedColumns: u.sorted,
                filteredColumns: a.grep(u.columns, function (v) {
                    return v.filters
                })
            };
            if (b.trigger(u.element, "dataBinding", r)) {
                return
            }
            if (!u.ajax && !u.ws && this.operationMode !== "client") {
                return
            }
            if (u.dataSource.transport.options && u.dataSource.transport.options.read) {
                u.dataSource.transport.options.read.url = this.url("selectUrl")
            }
            if (u._isServerOperation()) {
                u.showBusy()
            }
            u.dataSource.query(a.extend({
                page: q,
                pageSize: t ? s : n,
                sort: a.map(u.sorted, function (v) {
                    return {
                        field: v.member,
                        dir: v.order
                    }
                }),
                filter: a.map(a.grep(u.columns, function (v) {
                    return v.filters
                }), function (v) {
                    return u._translateFilterExpr(v, v.filters || [])
                }),
                group: a.map(u.groups, function (v) {
                    return {
                        field: v.member,
                        dir: v.order,
                        aggregates: p
                    }
                }),
                aggregates: p
            }, a.extend({}, r.data, o)))
        },
        _translateFilterExpr: function (o, p) {
            var q = this;
            return a.map(p, function (s) {
                if (s.filters) {
                    return {
                        logic: s.logic,
                        filters: q._translateFilterExpr(o, s.filters)
                    }
                } else {
                    var u = s.value;
                    if (o.type == "Number") {
                        u = parseFloat(u)
                    } else {
                        if (o.type == "Date") {
                            if (typeof u === "string") {
                                var r = /^\/Date\((.*?)\)\/$/.exec(u);
                                if (r) {
                                    u = new Date(parseInt(r[1]))
                                } else {
                                    var t = o.format ? /\{0(:([^\}]+))?\}/.exec(o.format)[2] : b.cultureInfo.shortDate;
                                    u = b.datetime.parse({
                                        value: u,
                                        format: t
                                    }).toDate()
                                }
                            }
                        }
                    }
                    return {
                        field: o.member,
                        operator: s.operator,
                        value: u
                    }
                }
            })
        },
        valueFor: function (o) {
            if (o.type == "Date") {
                return new Function("data", "var value = data." + o.member + '; if (!value) return null; return value instanceof Date? value : new Date(parseInt(value.replace(/\\/Date\\((.*?)\\)\\//, "$1")));')
            }
            return new Function("data", "return data" + (o.member ? "." + o.member : "") + ";")
        },
        displayFor: function (p) {
            var s = this.localization,
				r = this;
            if (p.commands) {
                var o = a.map(p.commands, function (u) {
                    return b.grid.ButtonBuilder.create(a.extend({
                        text: s[u.name]
                    }, u))
                });
                return function (u) {
                    return a.map(o, function (v) {
                        return v.build(a.extend({}, u, {
                            __page: r.currentPage,
                            __orderBy: r.orderBy || "",
                            __filter: r.filterBy || "",
                            __groupBy: r.groupBy || ""
                        }))
                    }).join("")
                }
            }
            if (!p.template) {
                var t = p.value ||
				function () {
				    return ""
				};
                var q = t = !p.data ? t : function (u) {
                    var w = p.value(u),
                        y = p.data,
                        z = "",
                        v, x;
                    for (v = 0, x = y.length; v < x; v++) {
                        if (w == y[v].Value) {
                            return y[v].Text
                        }
                    }
                    return z
                };
                if (p.format || p.type == "Date") {
                    t = function (u) {
                        var v = q(u);
                        return v == null ? "" : b.formatString(p.format || "{0:G}", v)
                    }
                }
                return p.encoded === false ? t : function (u) {
                    return e(t(u))
                }
            }
            return m(p.template)
        },
        insertFor: function (o) {
            return this.displayFor(o)
        },
        editFor: function (o) {
            return this.displayFor(o)
        },
        initializeColumns: function () {
            a.each(this.columns, a.proxy(function (q, r) {
                if (r.member !== n) {
                    r.value = this.valueFor(r)
                } else {
                    r.readonly = true
                }
                r.insert = this.insertFor(r);
                r.edit = this.editFor(r);
                r.display = this.displayFor(r);
                if (r.footerTemplate) {
                    r.footer = m(r.footerTemplate)
                }
                if (r.groupFooterTemplate) {
                    this.showGroupFooter = true;
                    r.groupFooter = m(r.groupFooterTemplate)
                }
                r.groupHeader = m("<#= Title #>: <#= Key #>");
                if (r.groupHeaderTemplate) {
                    r.groupHeader = m(r.groupHeaderTemplate)
                }
            }, this));
            var p = this.columns.length - 1;
            while (p >= 0) {
                var o = this.columns[p];
                if (o.hidden) {
                    p--;
                    continue
                }
                if (!o.attr) {
                    o.attr = ' class="t-last"';
                    break
                } else {
                    if (o.attr.indexOf("class") == -1) {
                        o.attr += ' class="t-last"';
                        break
                    } else {
                        o.attr = o.attr.replace('class="', 'class="t-last ');
                        break
                    }
                }
                p--
            }
            if (this.detail) {
                this.displayDetails = m(this.detail.template)
            }
        },
        bindData: function (r, u, t) {
            Array.prototype.push.apply(this.data, r);
            var s = this.pageOnScroll ? r.length : Math.min(this.pageSize, r.length);
            var p = this.columns.length;
            s = this.pageSize ? s : r.length;
            if (a.browser.msie) {
                a(this.element).find(".t-grid-content colgroup:first col").css("display", "")
            }
            for (var x = 0; x < s; x++) {
                var o = a.trim((this.detail ? "t-master-row" : "") + (x % 2 == 1 ? " t-alt" : ""));
                if (o) {
                    u.cat('<tr class="').cat(o).cat('">')
                } else {
                    u.cat("<tr>")
                }
                u.rep('<td class="t-group-cell"></td>', t).catIf('<td class="t-hierarchy-cell"><a class="t-icon t-plus" href="#" /></td>', this.detail);
                if (this.rowTemplate) {
                    u.cat('<td colspan="').cat(p).cat('">').cat(this.rowTemplate(r[x])).cat("</td>")
                } else {
                    for (var v = 0, w = this.columns.length; v < w; v++) {
                        var q = this.columns[v];
                        u.cat("<td").cat(q.attr).cat(">").cat(q.display(r[x]));
                        u.cat("</td>")
                    }
                }
                u.cat("</tr>")
            }
        },
        normalizeColumns: function () { },
        dataItem: function (o) {
            return (this.data || [])[this.$tbody.find("> tr:not(.t-grouping-row,.t-detail-row,.t-grid-new-row,.t-group-footer)").index(a(o))]
        },
        _colspan: function () {
            return this.groups.length + a.grep(this.columns, function (o) {
                return !o.hidden
            }).length + (this.detail ? 1 : 0)
        },
        bindTo: function (p) {
            var q = new b.stringBuilder();
            var o = this._colspan();
            if (p && p.length) {
                this.normalizeColumns(o);
                if (typeof p[0].hasSubgroups != "undefined") {
                    for (var r = 0, s = p.length; r < s; r++) {
                        this.bindGroup(p[r], o, q, 0)
                    }
                } else {
                    this.bindData(p, q)
                }
            } else {
                q.cat("<tr class='t-no-data'>").cat("<td colspan='").cat(o).cat("'>").cat(this.noRecordsTemplate ? this.noRecordsTemplate : this.localization.noRecords).cat("</td></tr>")
            }
            this.$tbody.html(q.string());
            if (this.onRowDataBound) {
                var t = jQuery.grep(this.$tbody[0].rows, function (u) {
                    return !a(u).is(".t-grouping-row, .t-group-footer, .t-footer-template")
                });
                for (var r = 0, s = this.data.length; r < s; r++) {
                    b.trigger(this.element, "rowDataBound", {
                        row: t[r],
                        dataItem: this.data[r]
                    })
                }
            }
        },
        updatePager: function () {
            var r = this.totalPages(this.total);
            var o = this.currentPage;
            var q = this.pageSize;
            this.$pager.find(".t-arrow-next").parent().add(this.$pager.find(".t-arrow-last").parent()).toggleClass("t-state-disabled", o >= r).removeClass("t-state-hover");
            this.$pager.find(".t-arrow-prev").parent().add(this.$pager.find(".t-arrow-first").parent()).toggleClass("t-state-disabled", o == 1).removeClass("t-state-hover");
            var p = this.localization;
            this.$pager.find(".t-page-i-of-n").each(function () {
                this.innerHTML = new b.stringBuilder().cat(p.page).cat('<input type="text" value="').cat(o).cat('" /> ').cat(b.formatString(p.pageOf, r)).string()
            });
            this.$pager.find(".t-page-size").each(function () {
                var s = '<div style="width: 50px;" class="t-dropdown t-header"><div class="t-dropdown-wrap t-state-default"><span class="t-input">' + q + '</span><span class="t-select"><span class="t-icon t-arrow-down">select</span></span></div></div>';
                this.innerHTML = s
            });
            this.$pager.find(".t-numeric").each(a.proxy(function (t, s) {
                this.numericPager(s, o, r)
            }, this));
            this.$pager.parent().find(".t-status-text").text(b.formatString(p.displayingItems, this.firstItemInPage(), this.lastItemInPage(), this.total))
        },
        numericPager: function (t, o, w) {
            var q = 10;
            var r = 1;
            if (o > q) {
                var v = (o % q);
                r = (v == 0) ? (o - q) + 1 : (o - v) + 1
            }
            var p = (r + q) - 1;
            p = Math.min(p, w);
            var u = new b.stringBuilder();
            if (r > 1) {
                u.cat('<a class="t-link">...</a>')
            }
            for (var s = r; s <= p; s++) {
                if (s == o) {
                    u.cat('<span class="t-state-active">').cat(s).cat("</span>")
                } else {
                    u.cat('<a class="t-link">').cat(s).cat("</a>")
                }
            }
            if (p < w) {
                u.cat('<a class="t-link">...</a>')
            }
            t.innerHTML = u.string()
        },
        $columns: function () {
            return this.$header.find("th:not(.t-hierarchy-cell,.t-group-cell)")
        },
        updateSorting: function () {
            this.sorted = [];
            a.each(this.orderBy.split("~"), a.proxy(function (o, q) {
                var r = q.split("-");
                var p = this.columnFromMember(r[0]);
                if (p) {
                    p.order = r[1];
                    this.sorted.push(p)
                }
            }, this));
            this.$columns().each(a.proxy(function (s, r) {
                var q = this.columns[s].order;
                var p = a(r).children("a.t-link");
                var o = p.children(".t-icon");
                if (!q) {
                    o.hide()
                } else {
                    if (o.length == 0) {
                        o = a('<span class="t-icon"/>').appendTo(p)
                    }
                    o.toggleClass("t-arrow-up", q == "asc").toggleClass("t-arrow-down", q == "desc").html("(" + (q == "asc" ? this.localization.sortedAsc : this.localization.sortedDesc) + ")").show()
                }
            }, this))
        },
        sanitizePage: function (p) {
            var o = parseInt(p, 10);
            if (isNaN(o) || o < 1) {
                return this.currentPage
            }
            return Math.min(o, this.totalPages())
        },
        totalPages: function () {
            return Math.ceil(this.total / this.pageSize)
        },
        firstItemInPage: function () {
            var o = this;
            return o.total > 0 ? o.pageOnScroll ? 1 : (o.currentPage - 1) * o.pageSize + 1 : 0
        },
        lastItemInPage: function () {
            return Math.min(this.currentPage * this.pageSize, this.total)
        },
        dataBind: function (o) {
            var p = this;
            if (!p.dataSource) {
                p._dataSource()
            } else {
                if (o && o.length) {
                    p.dataSource._group = a.map(p.groups, function (q) {
                        return {
                            field: q.member,
                            dir: q.order,
                            aggregates: p.aggregates
                        }
                    })
                }
            }
            p._clientBindingInProgress = true;
            try {
                p.dataSource.success(o || [])
            } finally {
                p._clientBindingInProgress = false
            }
        },
        bindFooter: function () {
            var r = this,
				o = r.$footer.find("td:not(.t-group-cell,.t-hierarchy-cell)"),
				p = r.aggregates,
				q = {
				    Sum: 0,
				    Count: 0,
				    Average: 0,
				    Max: 0,
				    Min: 0
				};
            a.each(r.columns, function (s) {
                if (this.footer) {
                    o.eq(s).html(this.footer(r._mapAggregates(p[this.member] || q)))
                }
            })
        },
        rebind: function (o) {
            var p = this;
            p.sorted = [];
            p.orderBy = "";
            p.filterBy = "";
            p.currentPage = 1;
            p.groupBy = "";
            p.groups = [];
            if (p.clearHeader) {
                p.clearHeader()
            }
            a.each(p.columns, function () {
                this.order = null;
                this.filters = null
            });
            a(".t-filter-options", p.element).find('input[type="text"], select').val("").removeClass("t-state-error").end().find("div.t-formatted-value").html("");
            a(".t-grid-filter", p.element).removeClass("t-active-filter");
            if (this.isAjax()) {
                p.data = []
            }
            if (!p._isServerOperation()) {
                p._dataSource()
            }
            p.ajaxRequest(o)
        },
        hideColumn: function (s) {
            var E = this,
				u = E.columns,
				t, r, F, v, B = E.$tbody.children("tr"),
				z, A, q, x, D = 0,
				p = a.browser,
				y = p.msie && parseInt(p.version) === 8,
				C, o, w = E.editing.mode;
            if (typeof s === "number") {
                s = u[s]
            } else {
                s = E.columnFromMember(s)
            }
            t = a.inArray(s, a.grep(u, function (G) {
                return !G.hidden
            }));
            if (t < 0 || !s) {
                return
            }
            r = a("col:not(.t-group-col,.t-hierarchy-col)", E.$header.parent().prev());
            if (E.scrollable) {
                a("col:not(.t-group-col,.t-hierarchy-col)", E.$footer).eq(t).remove();
                r.eq(t).remove();
                r = a("col:not(.t-group-col,.t-hierarchy-col)", E.$tbody.prev())
            }
            F = r.eq(t).remove()[0].style.width;
            E.$columns().filter(":visible").eq(t).hide();
            E.$footer.find("td:not(.t-group-cell):visible").eq(t).hide();
            for (x = 0, z = B.length; x < z; x++) {
                A = B.eq(x);
                if (A.is(".t-grouping-row,.t-detail-row")) {
                    q = A.children(":not(.t-group-cell):first,.t-detail-cell").last();
                    q.attr("colspan", parseInt(q.attr("colspan"), 10) - 1)
                } else {
                    if (A.hasClass("t-grid-edit-row")) {
                        if (w === "InLine" && !E.isAjax()) {
                            q = A.children(".t-edit-container");
                            q.attr("colspan", parseInt(q.attr("colspan"), 10) - 1);
                            q.find("col").eq(t).remove();
                            A = q.find("tr:first")
                        } else {
                            if (w === "InForm") {
                                q = A.children().first();
                                q.attr("colspan", parseInt(q.attr("colspan"), 10) - 1);
                                continue
                            }
                        }
                    }
                    A.children("td:not(.t-group-cell,.t-hierarchy-cell):visible").eq(t).hide()
                }
            }
            for (x = 0, z = r.length; x < z; x++) {
                if (x != t) {
                    v = r[x].style.width;
                    if (v && v.indexOf("%") === -1) {
                        D += parseInt(v)
                    } else {
                        D = 0;
                        break
                    }
                }
            }
            C = a(">table,>.t-grid-header table,>.t-grid-content>table, >.t-grid-footer>.t-grid-footer-wrap>table", E.element);
            if (D) {
                C.width(D)
            }
            if (y) {
                C.css("display", "inline-table");
                setTimeout(function () {
                    C.css("display", "table")
                }, 1)
            }
            s.hidden = true;
            s.width = F;
            o = s.attr;
            if (!o || o.indexOf("style") < 0) {
                o = (o || "") + ' style="display:none" '
            } else {
                o = s.attr.replace(/(style="(.*)?display):([^;]*)/i, "$1:none");
                if (o === s.attr) {
                    o = o.replace(/(style=")/i, "$1display:none;")
                }
            }
            s.attr = o;
            b.trigger(E.element, "repaint")
        },
        showColumn: function (q) {
            var z = this,
				r, s = z.columns,
				p, w = z.$tbody.children("tr"),
				x = a(">table,>.t-grid-header table,>.t-grid-content>table,>.t-grid-footer>.t-grid-footer-wrap>table", z.element),
				v, o, t, u;
            if (typeof q === "number") {
                q = s[q]
            } else {
                q = z.columnFromMember(q)
            }
            r = a.inArray(q, s);
            if (!q || !q.hidden) {
                return
            }
            p = a("col:not(.t-group-col,.t-hierarchy-col)", z.$header.parent().prev());
            i(p, s, r);
            if (z.scrollable) {
                p = a("col:not(.t-group-col,.t-hierarchy-col)", z.$tbody.prev());
                i(a("col:not(.t-group-col,.t-hierarchy-col)", z.$footer), s, r);
                i(p, s, r)
            }
            z.$columns().eq(r).show();
            z.$footer.find("td:not(.t-group-cell)").eq(r).show();
            for (t = 0, u = w.length; t < u; t++) {
                v = w.eq(t);
                if (v.is(".t-grouping-row,.t-detail-row")) {
                    o = v.children(":not(.t-group-cell):first,.t-detail-cell").last();
                    o.attr("colspan", parseInt(o.attr("colspan"), 10) + 1)
                } else {
                    if (v.hasClass("t-grid-edit-row")) {
                        if (z.editing.mode === "InLine" && !z.isAjax()) {
                            o = v.children(".t-edit-container");
                            o.attr("colspan", parseInt(o.attr("colspan"), 10) + 1);
                            i(o.find(">form>table>colgroup>col"), s, r);
                            v = o.find("tr:first")
                        } else {
                            if (z.editing.mode === "InForm") {
                                o = v.children().first();
                                o.attr("colspan", parseInt(o.attr("colspan"), 10) + 1);
                                continue
                            }
                        }
                    }
                    v.children("td:not(.t-group-cell,.t-hierarchy-cell)").eq(r).show()
                }
            }
            if (!q.width) {
                x.width("")
            } else {
                var y = parseInt(q.width, 10);
                for (t = 0, u = p.length; t < u; t++) {
                    if (p[t].style.width.indexOf("%") > -1) {
                        y = 0;
                        break
                    }
                    y += parseInt(p[t].style.width, 10)
                }
                if (y) {
                    x.width(y)
                }
            }
            q.hidden = false;
            delete q.width;
            if (q.attr) {
                q.attr = q.attr.replace(/(style="(.*)?)(display\s*:\s*none)\s*;?/i, "$1")
            }
            b.trigger(z.element, "repaint")
        },
        initializeContextMenu: function () {
            var u = this,
				r, q = b.fx.slide.defaults(),
				p = a.grep(u.columns, function (v) {
				    return v.title !== "" && v.includeInContextMenu !== false
				}),
				s = u.element.id + "_contextMenu",
				t, o;
            a(document).bind("mouseup", function (v) {
                if (t && v.which != 3 && a(v.target).closest("#" + s).length == 0) {
                    b.fx.rewind(q, t.find(".t-group"), {
                        direction: "bottom"
                    }, function () {
                        t.remove()
                    })
                }
            });
            u.$header.closest(".t-grid-header").bind("contextmenu", function (v) {
                if (t && t.is(":visible")) {
                    b.fx.rewind(q, t.find(".t-group"), {
                        direction: "bottom"
                    });
                    t.remove()
                }
                r = new b.stringBuilder();
                r.cat('<div class="t-animation-container t-menu t-menu-context" id="' + s + '" style="display:none">').cat('<ul class="t-group">');
                a.each(p, function () {
                    r.cat('<li class="t-item"><label class="t-link">').cat('<input type="checkbox" data-field="' + a.inArray(this, u.columns) + '"').catIf(' checked="checked"', !this.hidden).cat("/>").cat(this.title).cat("</label></li>")
                });
                r.cat("</ul></div>");
                t = a(r.string()).delegate("[type=checkbox]", "change", function () {
                    var w = a(this),
						x, y = w.data("field");
                    if (w.is(":checked")) {
                        u.showColumn(y);
                        if (u.onColumnShow) {
                            b.trigger(u.element, "columnShow", {
                                column: u.columns[y]
                            })
                        }
                    } else {
                        u.hideColumn(y);
                        if (u.onColumnHide) {
                            b.trigger(u.element, "columnHide", {
                                column: u.columns[y]
                            })
                        }
                    }
                    x = t.find(":checked");
                    x.attr("disabled", x.length == 1)
                }).appendTo(document.body);
                o = t.find(":checked");
                o.attr("disabled", o.length == 1);
                t.css({
                    left: v.clientX + a(document).scrollLeft(),
                    top: v.clientY + a(document).scrollTop()
                });
                b.fx.play(q, t.find(".t-group"), {
                    direction: "bottom"
                });
                return false
            })
        }
    };
    b.grid.ButtonBuilder = function (p) {
        var o = b.splitClassesFromAttr(p.attr);
        this.classNames = ["t-button"];
        var q = o.classes;
        if (q) {
            this.classNames.push(q);
            p.attr = o.attributes
        }
        if (p.name) {
            this.classNames.push("t-grid-" + p.name)
        }
        if (p.ajax) {
            this.classNames.push("t-ajax")
        }
        this.url = p.url ? m(unescape(p.url)) : function () {
            return "#"
        };
        this.content = function () {
            return p.text || ""
        };
        this.build = function (r) {
            return '<a href="' + this.url(r) + '" class="' + this.classNames.join(" ") + '" ' + (p.attr || "") + ">" + this.content() + "</a>"
        }
    };
    b.grid.ButtonBuilder.create = function (o) {
        return new (c[o.buttonType])(o)
    };

    function l(r, q) {
        var o = b.splitClassesFromAttr(q),
			p = o.classes,
			s = o.attributes;
        p = p ? " " + p : "";
        return '<span class="t-icon t-' + r + p + '"' + (s ? s : "") + "></span>"
    }
    b.grid.ImageButtonBuilder = function (o) {
        b.grid.ButtonBuilder.call(this, o);
        this.classNames.push("t-button-icon");
        this.content = function () {
            return l(o.name, o.imageAttr)
        }
    };
    b.grid.ImageTextButtonBuilder = function (o) {
        b.grid.ButtonBuilder.call(this, o);
        this.classNames.push("t-button-icontext");
        this.content = function () {
            return l(o.name, o.imageAttr) + o.text
        }
    };
    b.grid.BareImageButtonBuilder = function (o, p) {
        b.grid.ImageButtonBuilder.call(this, o, p);
        this.classNames.push("t-button-icon", "t-button-bare")
    };
    var c = {
        Text: b.grid.ButtonBuilder,
        ImageAndText: b.grid.ImageTextButtonBuilder,
        Image: b.grid.ImageButtonBuilder,
        BareImage: b.grid.BareImageButtonBuilder
    };
    a.fn.tGrid = function (o) {
        return b.create(this, {
            name: "tGrid",
            init: function (p, q) {
                return new b.grid(p, q)
            },
            options: o,
            success: function (p) {
                if (p.$tbody.find("> tr.t-no-data").length) {
                    p.ajaxRequest()
                }
            }
        })
    };
    a.fn.tGrid.defaults = {
        columns: [],
        plugins: [],
        currentPage: 1,
        pageSize: 10,
        localization: {
            addNew: "Add new record",
            "delete": "Delete",
            cancel: "Cancel",
            insert: "Insert",
            update: "Update",
            select: "Select",
            pageOf: "of {0}",
            displayingItems: "Displaying items {0} - {1} of {2}",
            edit: "Edit",
            noRecords: "No records to display.",
            page: "Page ",
            filter: "Filter",
            filterClear: "Clear Filter",
            filterShowRows: "Show rows with value that",
            filterAnd: "And",
            filterOr: "Or",
            filterStringEq: "Is equal to",
            filterStringNe: "Is not equal to",
            filterStringStartsWith: "Starts with",
            filterStringSubstringOf: "Contains",
            filterStringNotSubstringOf: "Does not contain",
            filterStringEndsWith: "Ends with",
            filterNumberEq: "Is equal to",
            filterNumberNe: "Is not equal to",
            filterNumberLt: "Is less than",
            filterNumberLe: "Is less than or equal to",
            filterNumberGt: "Is greater than",
            filterNumberGe: "Is greater than or equal to",
            filterDateEq: "Is equal to",
            filterDateNe: "Is not equal to",
            filterDateLt: "Is before",
            filterDateLe: "Is before or equal to",
            filterDateGt: "Is after",
            filterDateGe: "Is after or equal to",
            filterEnumEq: "Is equal to",
            filterEnumNe: "Is not equal to",
            filterForeignKeyEq: "Is equal to",
            filterForeignKeyNe: "Is not equal to",
            filterBoolIsTrue: "is true",
            filterBoolIsFalse: "is false",
            filterSelectValue: "-Select value-",
            filterOpenPopupHint: "Open the calendar popup",
            groupHint: "Drag a column header and drop it here to group by that column",
            deleteConfirmation: "Are you sure you want to delete this record?",
            sortedAsc: "sorted ascending",
            sortedDesc: "sorted descending",
            ungroup: "ungroup"
        },
        queryString: {
            page: "page",
            size: "size",
            orderBy: "orderBy",
            groupBy: "groupBy",
            filter: "filter",
            aggregates: "aggregates"
        }
    }
})(jQuery);